package net.apexes.wsonrpc.server.nano.http.threading;

import net.apexes.wsonrpc.server.nano.http.ClientHandler;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

/**
 * @author hedyn
 */
public class CachedThreadPoolAsyncRunner implements IAsyncRunner {

    private final ExecutorService executor;

    public CachedThreadPoolAsyncRunner(ThreadFactory threadFactory) {
        executor = Executors.newCachedThreadPool(threadFactory);
    }

    @Override
    public void closeAll() {
        executor.shutdownNow();
    }

    @Override
    public void closed(ClientHandler clientHandler) {
    }

    @Override
    public void exec(ClientHandler code) {
        executor.execute(code);
    }
}
